<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>{$title} - <tp:sitename /></title>
    <meta name="keywords" content="{$keywords}" />
    <meta name="description" content="{$description}" />
    <link rel="shortcut icon" href="__PUBLIC__/images/favicon.ico" type="image/x-icon" /> 
    <link rel="stylesheet" href="__PUBLIC__/css/style_version1.css" type="text/css" />
    <link href="__PUBLIC__/css/member.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="__PUBLIC__/css/topic.css" type="text/css" />
    <script src="__PUBLIC__/js/jquery.js" type="text/javascript"></script>
    
    <script type="text/javascript" src="__DATA__/editor/ueditor/ueditormini.config.js"></script>
	<script type="text/javascript" src="__DATA__/editor/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript">
    $(function(){
        var ue = UE.getEditor('editor',{
            serverUrl :"{:U('Public/editorMethod')}"
        });
    })
    </script>
</head> 
<body> 

<include file="Public:header" />

<div class="container clearfix">
    
    <include file="Member:left" />
    
    <div class="member_main">
        <div class="perInfo">
            <div class="titleInfoBorder">
                <span>{$title}</span>
            </div>
        </div>
        <div class="setting-right-wrap wrap-boxes settings" style="padding:0">

            <div class="detail topic_add">
            	<!--<form action="" method="post">-->
                <ul class="topic_add_ul">
                    <li>
                        <div class="clearfix">
                            <div class="label_right">
                            <input class="text" type="text" id="title" placeholder="请输入标题" data-null="请输入标题" autocomplete="off" tabindex="1" value="{$info.title}" onfocus="focusInputTopicArea($(this))" onblur="blurInputTopicArea($(this))" data-minlength="5">
                            </div>   
                            <label><span class="must">*</span>标题：</label>
                        </div>
                        <div class="validate"><span class="Validform_checktip Validform_wrong hide"></span></div>
                    </li>
                    <li>
                        <div class="clearfix">
                            <div class="label_right" id="cats">
                            <select id="cate" name="cate"  class="rlf-select" hidefocus="true" autocomplete="off">
                                <option value="0">请选择分类</option>
                            	<volist name="cate" id="v">
                                <option value="{$v.id}" <if condition="$info['cid'] eq $v['id']">selected="selected"</if> >{$v.delimiter}{$v.name}</option>
								</volist>
                            </select>
                            </div>   
        
                            <label><span class="must">*</span>分类：</label>
                        </div>
                        <div class="validate"><span class="Validform_checktip Validform_wrong hide"></span></div>
                    </li>
                    <li>
                        <div class="clearfix">
                            <div class="label_right">
                                <script id="editor" type="text/plain" style="width:663px;height:200px;">{$info.content}</script>
                            </div>   
                            <label><span class="must">*</span>内容：</label>
                        </div>
                        <div class="validate" id="tip_content"><span class="Validform_checktip Validform_wrong hide"></span></div>
                    </li>
                    <li class="clearfix" style="margin-bottom: 20px">
                        <div class="label_right">
                            <div class="tags" id="tags" tabindex="1">
                                <php>if($info['tag']){</php>
                            	<php>$tag = explode(',',$info['tag']);</php>
                                <volist name="tag" id="t">
                                    <span class="tag"><span>{$t}</span><button class="close" type="button">×</button></span>
                                </volist>
                                <php>}</php>
                                <input id="form-field-tags" type="text" placeholder="请输入标签..." value="Tag Input Control" name="tags" style="display: none;">
                                <input type="text" placeholder="请输入标签..." class="tags_enter" autocomplete="off">
                            </div>
                        </div>   
                        <label><span class="must"></span>标签：</label>
                    </li>
                    <li class="clearfix">
                        <div class="label_right">
                            <div id="js-tags" class="taglist clearfix">
                                <volist name="tags" id="v">
                                <a class="list-tag" data-id="{$v.tag_id}" href="javascript:;" style="margin:0 6px 10px 0">{$v.tag_name}</a>
                                </volist>
                            </div>
                        </div>   
                        <label><span class="must"></span></label>
                    </li>
        
                    <li class="clearfix"></li>
                    
                    <li class="clearfix">
                        <div class="label_right">
                            <input type="button" class="btn" value="提 交" tabindex="3" id="btn_submit" style="font-size: 14px; width:100px; height:36px;" autocomplete="off">
                        </div>   
                        <label></label>
                    </li>
                </ul>
                <!--</form>-->
            </div>

        </div>
    </div>
    
</div>
<include file="Public:footext" />
<include file="Member:mfooter" />
<script type="text/javascript">

function addTag(tag) {
//        var tag = obj.val();
	var length = $("span.tag").length;
	if (length > 8) {
		alert("标签个数不能超过8个！");
		return false;
	}
	if (tag != '') {
		var i = 0;
		$(".tag").each(function() {
			if ($(this).text() == tag + "×") {
				$(this).addClass("tag-warning");
				setTimeout("removeWarning()", 400);
				i++;
			}
		})
		$(".tags_enter").val('');
		if (i > 0) { //说明有重复
			return false;
		}
		if (tag.length > 10) {
			alert("标签长度不能大于10个字符！");
			return false;
		}
		$("#form-field-tags").before("<span class='tag'><span>" + tag + "</span><button class='close' type='button'>×</button></span>"); //添加标签
	}
}
function removeWarning() {
	$(".tag-warning").removeClass("tag-warning");
}

$(function() {
	/*******标签tag******/
	$(".tags_enter").blur(function() { //焦点失去触发
		addTag($(this).val());
		$(this).parents(".tags").css({"border-color": "#d5d5d5"})
	}).keydown(function(event) {
		var key_code = event.keyCode;
		if (key_code == 13) { //enter
			addTag($(this).val());
		}
	});
	$(".close").live("click", function() {
		$(this).parent(".tag").remove();
	});
	$(".tags").click(function() {
		$(".tags_enter").focus();
		$(this).css({"border-color": "#f59942"})
	}).blur(function() {
		$(this).css({"border-color": "#d5d5d5"})
	})
	/*******分类******/
	$("#cats").children("em").click(function() {
		$(this).addClass("current").siblings("em").removeClass("current")
	})
	/*******更换验证码******/
	/*$(".getcode_gg").click(function() {
		$("#getcode_gg").attr("src", '/other/js/group/code_gg.php?' + Math.random());
	});*/
	/*******提交******/
	$("#btn_submit").click(function() {
		blurInputTopicArea($("#title"), 1);
		//blurInputTopicArea($("#code"), 1);
		
		var i = 0;
		$(".Validform_wrong").each(function() {
			if ($(this).css("display") == 'inline') {
				i++;
			}
		})
		
		if (i > 0) {
			return false;
		}
		var title = $("#title").val();
		//var cat_id = $("#cats").children("em.current").attr("data-id");
		var cat_id = $('#cate option:selected').val();
		if(cat_id == "0"){
			alert('请选择分类');
			return false;
		}
		var tags = "";
		$("#tags").children(".tag").each(function() {
			tags += $(this).children("span").text() + ",";
		});
		var tags = tags.substring(0,tags.length-1);
		var content = UE.getEditor('editor').getContent();
		//var content = $("#content").val();
		//var file_path = $("#upload_rs").text();
		//var code = $("#code").val();
		var id = "{$info.id}";
		//alert(content);
		$.post("{:U('Member/topic_post')}", {
			title: title,
			cid: cat_id,
			content: content,
			tags: tags,
			//code: code,
			id:id
		},
		function(data) {
			if (data.error == -1) {
				//showWindowBox();
				alert("您还未登录呢！");
				$("#windown_box").attr("data-func", "addClickFunc('#btn_submit')");
				return false;
			}
			if (data.error == '') {
				showSuccessTip(data.tip);
				var url = "{:U('Member/topic')}";
				setTimeout("goUrl('" + url + "')", 1500);
			} else {
				alert(data.error);
			}

		}, "json")
	})
	/*******添加推荐标签******/
	$("#js-tags").children(".list-tag").click(function() {
		var tag = $(this).text();
		addTag(tag);
	})
})
function focusInputTopicArea(obj) {
	obj.next(".error").hide();
	obj.addClass("form_input-focus");
	obj.prev("div").addClass("item_tip_focus");
	obj.nextAll(".grey").show();
	obj.nextAll(".icon-loginright").hide();
}
function focusInputTopicArea(obj) {
	obj.parent().parent().next(".validate").children("span").hide();
	obj.css({"border-color": "#cccccc"})
}

function blurInputTopicArea(obj, is_sub) {
	var val = obj.val();
	var minlength = obj.attr("data-minlength");
	var maxlength = obj.attr("data-maxlength");
	var length = obj.attr("data-length");
	var type = obj.attr("data-type");
	var time_error = 0;
	if (val == "") {
		var tip_null = obj.attr("data-null");
		getTopicError(obj, tip_null);

	} else {
		if (val.length != length && length > 0) {
			getTopicError(obj, "长度必须为" + length + "位");
			time_error++;
		}
		if (minlength > 0 && val.length < minlength) {
			getTopicError(obj, "长度至少" + minlength + "位");
			time_error++;
		}
		if (maxlength > 0 && val.length > maxlength) {
			getTopicError(obj, "长度最多" + maxlength + "位");
			time_error++;
		}

	}
}
function getTopicError(obj, tip) {
	obj.parent().parent().next(".validate").children("span").text(tip).show();
	obj.css({"border-color": "#cc0000"})
}
</script>
</body>
</html>
